package com.tangye.massageshop.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tangye.massageshop.repository.WorkerRepository;
import com.tangye.massageshop.entity.WorkerEntity;
import com.tangye.massageshop.mapper.WorkerMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

@Service
public class WorkerRepositoryImpl implements WorkerRepository {

    @Resource
    private WorkerMapper workerMapper;
    @Override
    public List<WorkerEntity> selectWorkersPage(WorkerEntity workerEntity) {
        QueryWrapper<WorkerEntity> qw = new QueryWrapper<>();

        if (Objects.nonNull(workerEntity.getCompanyId())) {
            qw.eq("company_id", workerEntity.getCompanyId());
        }
        if (Objects.nonNull(workerEntity.getShopId())) {
            qw.eq("shop_id", workerEntity.getShopId());
        }
        if (StringUtils.isNotBlank(workerEntity.getWorkerName())) {
            qw.like("worker_name", workerEntity.getWorkerName());
        }


        Page<WorkerEntity> page = new Page<>(workerEntity.getPageNum(), workerEntity.getPageSize());
        Page<WorkerEntity> resultPage = workerMapper.selectPage(page, qw);
        return resultPage.getRecords();
    }
}
